import random


def bucket_sort(li, n=100, max_num=100):
    buckets = [[] for _ in range(n)]
    for var in li:
        i = min(var // (max_num // n), n - 1)
        buckets[i].append(var)  # var加入桶
        for j in range(len(buckets[i]) - 1, 0, -1):
            if buckets[i][j] < buckets[i][j - 1]:
                buckets[i][j], buckets[i][j - 1] = buckets[i][j - 1], buckets[i][j]
            else:
                break
    sorted_list = []
    for buc in buckets:
        sorted_list.extend(buc)
    return sorted_list


li = [random.randint(1, 100) for _ in range(10)]
print(li)
li = bucket_sort(li, n=100, max_num=100)
print(li)
